<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>jq</title>
	<script src="jquery.js"></script>
	
</head>
<style>
	
</style>


<body>
	<div class="div1">
		<h1>aaaaaaaaaaaaaaaaaaa</h1>
		<h1>bbbbbbbbbbbbbbbbbb</h1>
		<h1>cccccccccccccccccccc</h1>
	</div>
	<hr>
	<div class="div2">
		<h1>aaaaaaaaaaaaaaaaaaa</h1>
		<h1>bbbbbbbbbbbbbbbbbb</h1>
		<h1>cccccccccccccccccccc</h1>
	</div>
	<hr>
	<div><h1>sssssssssssssssssssssssss</h1></div>
</body>
<script>
	
	//$('.div2 h1:first').css({'color':'#f00'});
	//$('div h1:first-child').css({'color':'#f00'}); //每个div第一个h1
	//$('div h1:last-child').css({'color':'#f00'});  //每个div最后一个h1
	//$('div h1:nth-child(2)').css({'color':'#f00'});	 //每个div第二个h1
	$('div h1:only-child').css({'color':'#f00'}); //div中只有1个h1的标签
</script>
</html>